package fr.oz.core.datas 
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	/**
	 * ...
	 * @author Fazermokeur
	 */
	public class UserProfiles extends EventDispatcher
	{
		private var _profile:XML;
		private var loader:URLLoader;
		
		public static var profils:Vector.<ProfilListDatas>
		public static var a_active : Array = [];
		public static var WAKE_TIME:Array;
		
		public function UserProfiles() 
		{
			
		}
		
		public function init(url:String):void
		{
			loader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, handleComplete);
			loader.addEventListener(IOErrorEvent.IO_ERROR, handleError);
			
			loader.load(new URLRequest(url));
		}
		
		private function handleError(e:IOErrorEvent):void 
		{
			trace("3: ERROR de chargement : " + e.text);
		}
		
		private function handleComplete(e:Event):void 
		{
			_profile = new XML(loader.data);
			profils = new Vector.<ProfilListDatas>();
			
			genProfilListData();
			checkActiveProfile();
			
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		private function genProfilListData():void
		{
			var node:XML;
			var profil:ProfilDatas;
			for each(node in _profile.wakeUp.profil)
			{
				profil = new ProfilListDatas(node);
				profils.push( profil );
			}
		}
		
		private function checkActiveProfile():void
		{
			var node:XML;
			for each(node in _profile.wakeUp.profil) {
				if (node.@active == true) {
					a_active.push(node);
				}
			}
			
		}
		
		public static function getActiveProfiles():Array {	return a_active;	};
	}

}